/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bungabungaball.emitter;

import org.newdawn.slick.Image;
import org.newdawn.slick.particles.Particle;
import org.newdawn.slick.particles.ParticleEmitter;
import org.newdawn.slick.particles.ParticleSystem;

/**
 * A ParticleEmitter that makes a red effect around the player on catching some
 * PowerUp
 *
 * @author Ingo Klose, Stephan Meyer, Sebastian Lehmann
 * @version 1.0
 */
public class PowerUp implements ParticleEmitter {

    /**
     * The x coordinate of the center of the fire effect
     */
    private int x;
    /**
     * The y coordinate of the center of the fire effect
     */
    private int y;
    /**
     * The particle emission rate
     */
    private int interval = 1000;
    /**
     * Time til the next particle
     */
    private int timer;
    /**
     * The size of the initial particles
     */
    private float size = 10;
    /**
     * The radius of the ring
     */
    private int radius = 30;
    /**
     * Is the visual effect completed?
     */
    private boolean completed = false;
    /**
     * Number
     */
    private int anzahl = 0;

    /**
     * Update the visual effect
     *
     * @param system
     * @param delta
     */
    @Override
    public void update(ParticleSystem system, int delta) {
        timer -= delta;
        if (timer <= 0) {
            timer = interval;
            for (int i = 0; i < 20; i++) {
                double a = Math.PI * 2 * Math.random();

                float parX = (float) (radius * Math.cos(a));
                float parY = (float) (radius * Math.sin(a));
                Particle p = system.getNewParticle(this, 1000);
                p.setColor(255, 0, 0, 1.0f);
                p.setPosition(x, y);
                p.setSize(10);
                p.setVelocity(parX, parY, 0.01f);
            }
            if (!completed && anzahl == 1) {
                completed = true;
                anzahl = 0;
            } else {
                anzahl = 1;
            }
        }
    }

    /**
     *
     * @param particle
     * @param delta
     */
    @Override
    public void updateParticle(Particle particle, int delta) {
//        if (particle.getLife() > 600) {
//            particle.adjustSize(0.07f * delta);
//        } else {
//            particle.adjustSize(-0.04f * delta * (size / 40.0f));
//        }
        //float c = 0.002f * delta;
        //particle.adjustColor(c, c, c, -c / 4);
    }

    /**
     * Get the variable completed
     *
     * @return Returns completed
     */
    @Override
    public boolean completed() {
        return completed;
    }

    /**
     *
     */
    @Override
    public void wrapUp() {
    }

    /**
     *
     */
    @Override
    public void resume() {
    }

    /**
     *
     * @return Returns true
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    /**
     *
     * @param enabled
     */
    @Override
    public void setEnabled(boolean enabled) {
    }

    /**
     *
     * @return Returns false
     */
    @Override
    public boolean useAdditive() {
        return false;
    }

    /**
     *
     * @return Returns null
     */
    @Override
    public Image getImage() {
        return null;
    }

    /**
     *
     * @return Returns false
     */
    @Override
    public boolean isOriented() {
        return false;
    }

    /**
     *
     * @param system
     * @return Returns false
     */
    @Override
    public boolean usePoints(ParticleSystem system) {
        return false;
    }

    /**
     *
     */
    @Override
    public void resetState() {
    }
}
